<%@page import="helpers.DateHelper"%>
<%@page import="helpers.StringHelper"%>
<%@page import="com.google.appengine.api.blobstore.BlobKey"%>
<%@page import="com.google.appengine.api.images.ImagesServiceFactory"%>
<%@page import="com.google.appengine.api.images.ImagesService"%>
<%@page import="java.util.Locale"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="models.GeoModel"%>
<%@page import="models.DealModel"%>
<%@page import="java.util.ArrayList"%>
<%@page import="models.DealEmailModel"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% 
DealEmailModel dealEmail = (DealEmailModel) request.getAttribute("dealEmail");
ArrayList<DealModel> deals = (ArrayList<DealModel>) request.getAttribute("deals");
GeoModel city = (GeoModel) request.getAttribute("city");
ImagesService imagesService = ImagesServiceFactory.getImagesService(); 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Email</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body leftmargin="0" topmargin="0">
	<div class="ii gt adP adO" id=":s">
		<div id=":t">
			<div class="adM"></div>
			<div style="text-align: center; background: #67FFFF; margin: 0px">
				<center>
					<div
						style="width: 100%; background: #67FFFF; font-family: Arial, Helvetica, sans-serif">
						<table width="584" cellspacing="0" cellpadding="0">
							<tbody>
								<tr style="background: #333333">
									<td width="219" align="left"
										style="text-align: left; padding: 8px"><a target="_blank"
										title="orabuy.com"
										href="<%=UrlHelper.getServerUrl(request) %>"
										style="text-decoration: none"><img width="189" height="43"
											border="0" title="www.orabuy.com"
											style="display: block; padding: 7px" alt="www.orabuy.com"
											src="<%=UrlHelper.getServerUrl(request) %>/images/logo.png">
									</a><a target="_blank" title="orabuy.com"
										href="<%=UrlHelper.getServerUrl(request) %>"
										style="text-decoration: none"></a>
									</td>
									<td width="321" align="left"><font size="  4pt"
										color="#FFFFFF">
											<p
												style="border-left: solid #545454 1.0pt; min-height: 50px; padding-left: 10px">
												Các khuyến mãi tại<br> <strong><font size="5"><%=city != null ? city.getName() : "" %></font>
												</strong>
											</p> </font>
									</td>
									<td width="121" align="left"
										style="font-size: 13px; color: #fff; text-align: right; padding-right: 10px; vertical-align: middle"><%=DateHelper.dateToString(dealEmail.getDate(), "dd/MM/yyyy")  %></td>
								</tr>
								<tr>
									<td align="center"
										style="border-top: 5px solid #4bc1de; background: #fff"
										colspan="3">&nbsp;</td>
								</tr>
								<tr>
									<td align="center" style="background: #fff" colspan="3">
										<table width="100%" cellspacing="0" cellpadding="0" border="0">
											<tbody>
												<% if (deals.size() > 0) { %>
												<tr>
													<td align="left" style="padding: 0px 15px" colspan="3">
														<table width="100%" cellspacing="0" cellpadding="0"
															border="0"
															style="background: #efeeee; margin-bottom: 15px">
															<tbody>
																<tr>
																	<td align="center" style="padding: 10px 23px 10px 25px"
																		scope="col"><a target="_blank"
																		title="<%=deals.get(0).getShortName() %>"
																		href="<%=UrlHelper.getServerUrl(request) + "/email-redirect/" + deals.get(0).getDealId() + "/" + deals.get(0).getAlias() + ".html" %>"
																		style="text-decoration: none"><span
																			style="color: #0792bd; text-decoration: none; font-size: 17px"><strong><%=deals.get(0).getShortName() %></strong>
																		</span>
																	</a>
																	</td>
																</tr>
																<tr>
																	<td align="center" style="padding: 0px 10px"><a
																		target="_blank" title="maindeal_name"
																		href="<%=UrlHelper.getServerUrl(request) + "/email-redirect/" + deals.get(0).getDealId() + "/" + deals.get(0).getAlias() + ".html" %>"
																		style="text-decoration: none">
																		<%
										                                		String img = "";
										                                		if(deals.get(0).getImageDeal()!=null&&deals.get(0).getImageDeal().length()>0){
										                                			String[] split = deals.get(0).getImageDeal().split(",");
										                                			if(split.length>0){
										                                				img = split[0];			
										                                			}else{
										                                				img = deals.get(0).getImageDeal();
										                                			}
										                                	
										                                			BlobKey blobKey = new BlobKey(img);
										                                			%>
																		<img width="560"
																			title="<%=deals.get(0).getShortName() %>"
																			style="padding: 3px; border: #939598 solid 1px; display: block; background: #fff"
																			alt="<%=deals.get(0).getShortName() %>"
																			src="<%=imagesService.getServingUrl(blobKey) %>">
																	<% } %>
																	</a>
																	</td>
																</tr>
																<tr>
																	<td align="center"><table width="568"
																			cellspacing="0" cellpadding="0" border="0">
																			<tbody>
																				<tr style="background: #cccccc; font-size: 10px">
																					<td width="17%" align="center" scope="col"
																						style="padding: 3px">Giảm giá</td>
																					<td width="42%" align="center" scope="col"
																						style="padding: 3px; border-left: 1px #666 solid">Giá
																						bán</td>
																					<td width="41%" align="right" scope="col"
																						style="padding: 3px; border-left: 1px #666 solid"
																						rowspan="2"><span style="padding: 10px 10px"><a
																							target="_blank"
																							href="<%=UrlHelper.getServerUrl(request) + "/email-redirect/" + deals.get(0).getDealId() + "/" + deals.get(0).getAlias() + ".html" %>"
																							style="text-decoration: none"><img border="0"
																								alt="<%=deals.get(0).getShortName() %>"
																								src="<%=UrlHelper.getServerUrl(request) + "/images/btn_detail.png" %>">
																						</a>
																					</span>
																					</td>
																				</tr>
																				<tr
																					style="background: #cccccc; font-size: 16px; font-weight: bolder">
																					<td align="center" scope="col" style="padding: 3px">
																					<%
																					NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);      
													                        		int less =  (deals.get(0).getPrice() - deals.get(0).getPriceDiscount());
													                        		int discount = less*100/deals.get(0).getPrice();
																					%>
																					<%=discount %>  %
																					</td>
																					<td align="center" scope="col"
																						style="padding: 3px; border-left: 1px #666 solid"><span><%=deals.get(0).getPriceDiscount() %>đ</span>
																					</td>
																				</tr>
																			</tbody>
																		</table>
																	</td>
																</tr>
																<tr>
																	<td align="center"
																		style="color: #666; font-size: 11px; text-align: left; padding: 10px 20px 10px 23px"><%=StringHelper.cutString(StringHelper.html2text(deals.get(0).getDescription()), 100) %></td>
																</tr>
															</tbody>
														</table></td>
												</tr>
												
												<% } %>
												<tr>
												</tr>
												<% if (deals.size() > 1) { %>
												<% for (int i = 1; i < deals.size(); i=i+2) {%>
												<tr>
													<td align="left" style="padding-left: 15px">
														<table width="303" cellspacing="0" cellpadding="0" border="0" style="background: #efeeee; margin-bottom: 15px">
															<tbody>
																<tr>
																	<td align="center" style="padding: 10px 20px 10px 23px"
																		scope="col"><a target="_blank"
																		title="<%=deals.get(i).getShortName() %>"
																		href="<%=UrlHelper.getServerUrl(request) + "/email-redirect/" + deals.get(i).getDealId() + "/" + deals.get(i).getAlias() + ".html" %>"
																		style="text-decoration: none"><span
																			style="color: #0792bd; text-decoration: none; font-size: 14px"><strong><%=deals.get(i).getShortName() %></strong>
																		</span>
																	</a>
																	</td>
																</tr>
																<tr>
																	<td align="center" style="padding: 0px 10px"><a
																		target="_blank"
																		title="<%=deals.get(i).getShortName() %>"
																		href="<%=UrlHelper.getServerUrl(request) + "/email-redirect/" + deals.get(i).getDealId() + "/" + deals.get(i).getAlias() + ".html" %>"
																		style="text-decoration: none">
																		<%
										                                		String img = "";
										                                		if(deals.get(i).getImageDeal()!=null&&deals.get(i).getImageDeal().length()>0){
										                                			String[] split = deals.get(i).getImageDeal().split(",");
										                                			if(split.length>0){
										                                				img = split[0];			
										                                			}else{
										                                				img = deals.get(i).getImageDeal();
										                                			}
										                                	
										                                			BlobKey blobKey = new BlobKey(img);
										                                			%>
																		<img width="250"
																			title="<%=deals.get(i).getShortName() %>"
																			style="padding: 3px; border: #939598 solid 1px; display: block; background: #fff"
																			alt="<%=deals.get(i).getShortName() %>"
																			src="<%=imagesService.getServingUrl(blobKey) %>">
																		<% } %>
																	</a>
																	</td>
																</tr>
																<tr>
																	<td align="center"><table width="257"
																			cellspacing="0" cellpadding="0" border="0">
																			<tbody>
																				<tr style="background: #cccccc; font-size: 10px">
																					<td width="30%" align="center" scope="col"
																						style="padding: 3px">Giảm giá</td>
																					<td width="70%" align="center" scope="col"
																						style="padding: 3px; border-left: 1px #666 solid">Giá
																						bán</td>
																				</tr>
																				<tr
																					style="background: #cccccc; font-size: 16px; font-weight: bolder">
																					<td align="center" scope="col" style="padding: 3px">
																					<%
																					NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);      
													                        		int less =  (deals.get(i).getPrice() - deals.get(i).getPriceDiscount());
													                        		int discount = less*100/deals.get(i).getPrice();
																					%>
																					<%=discount %> %</td>
																					<td align="center" scope="col"
																						style="padding: 3px; border-left: 1px #666 solid"><%=deals.get(i).getPriceDiscount() %>đ</td>
																				</tr>
																			</tbody>
																		</table>
																	</td>
																</tr>
																<tr>
																	<td align="left" style="padding: 10px 10px"><table
																			width="100%" cellspacing="0" cellpadding="0"
																			border="0">
																			<tbody>
																				<tr>
																					<td width="52%" style="padding-left: 10px"><a
																						target="_blank"
																						href="<%=UrlHelper.getServerUrl(request) + "/email-redirect/" + deals.get(i).getDealId() + "/" + deals.get(i).getAlias() + ".html" %>"
																						style="text-decoration: none"><img border="0"
																							alt="<%=deals.get(i).getShortName() %>"
																							src="<%=UrlHelper.getServerUrl(request) + "/images/btn_detail.png" %>">
																					</a>
																					</td>
																					<td width="49%" align="right"
																						style="padding-right: 10px"><strong><span
																							style="font-size: 12px; color: #666"><%=(deals.get(i).getProductType()==0?"Giao Phiếu":"Giao Hàng") %></span>
																					</strong>
																					</td>
																				</tr>
																			</tbody>
																		</table>
																	</td>
																</tr>
															</tbody>
														</table>
														
													</td>
													<td>&nbsp;</td>
													<td align="right" style="padding-right: 15px">
														<% if (i + 1 < deals.size()) { %>
														<table width="303" cellspacing="0" cellpadding="0" border="0" style="background: #efeeee; margin-bottom: 15px">
															<tbody>
																<tr>
																	<td align="center" style="padding: 10px 20px 10px 23px"
																		scope="col"><a target="_blank"
																		title="<%=deals.get(i).getShortName() %>"
																		href="<%=UrlHelper.getServerUrl(request) + "/email-redirect/" + deals.get(i + 1).getDealId() + "/" + deals.get(i + 1).getAlias() + ".html" %>"
																		style="text-decoration: none"><span
																			style="color: #0792bd; text-decoration: none; font-size: 14px"><strong><%=deals.get(i + 1).getShortName() %></strong>
																		</span>
																	</a>
																	</td>
																</tr>
																<tr>
																	<td align="center" style="padding: 0px 10px"><a
																		target="_blank"
																		title="<%=deals.get(i + 1).getShortName() %>"
																		href="<%=UrlHelper.getServerUrl(request) + "/" + deals.get(i + 1).getDealId() + "/" + deals.get(i + 1).getAlias() + ".html" %>"
																		style="text-decoration: none">
																		<%
										                                		img = "";
										                                		if(deals.get(i + 1).getImageDeal()!=null&&deals.get(i+1).getImageDeal().length()>0){
										                                			String[] split = deals.get(i + 1).getImageDeal().split(",");
										                                			if(split.length>0){
										                                				img = split[0];			
										                                			}else{
										                                				img = deals.get(i + 1).getImageDeal();
										                                			}
										                                	
										                                			BlobKey blobKey = new BlobKey(img);
										                                			%>
																		<img width="250"
																			title="<%=deals.get(i + 1).getShortName() %>"
																			style="padding: 3px; border: #939598 solid 1px; display: block; background: #fff"
																			alt="<%=deals.get(i + 1).getShortName() %>"
																			src="<%=imagesService.getServingUrl(blobKey) %>">
																		<% } %>
																	</a>
																	</td>
																</tr>
																<tr>
																	<td align="center"><table width="257"
																			cellspacing="0" cellpadding="0" border="0">
																			<tbody>
																				<tr style="background: #cccccc; font-size: 10px">
																					<td width="30%" align="center" scope="col"
																						style="padding: 3px">Giảm giá</td>
																					<td width="70%" align="center" scope="col"
																						style="padding: 3px; border-left: 1px #666 solid">Giá
																						bán</td>
																				</tr>
																				<tr
																					style="background: #cccccc; font-size: 16px; font-weight: bolder">
																					<td align="center" scope="col" style="padding: 3px">
																					<%
																					nf = NumberFormat.getNumberInstance(Locale.GERMAN);      
													                        		less =  (deals.get(i + 1).getPrice() - deals.get(i + 1).getPriceDiscount());
													                        		discount = less*100/deals.get(i + 1).getPrice();
																					%>
																					<%=discount %> %</td>
																					<td align="center" scope="col"
																						style="padding: 3px; border-left: 1px #666 solid"><%=deals.get(i + 1).getPriceDiscount() %>đ</td>
																				</tr>
																			</tbody>
																		</table>
																	</td>
																</tr>
																<tr>
																	<td align="left" style="padding: 10px 10px"><table
																			width="100%" cellspacing="0" cellpadding="0"
																			border="0">
																			<tbody>
																				<tr>
																					<td width="52%" style="padding-left: 10px"><a
																						target="_blank"
																						href="<%=UrlHelper.getServerUrl(request) + "/email-redirect/" + deals.get(i+1).getDealId() + "/" + deals.get(i+1).getAlias() + ".html" %>"
																						style="text-decoration: none"><img border="0"
																							alt="<%=deals.get(i+1).getShortName() %>"
																							src="<%=UrlHelper.getServerUrl(request) + "/images/btn_detail.png" %>">
																					</a>
																					</td>
																					<td width="49%" align="right"
																						style="padding-right: 10px"><strong><span
																							style="font-size: 12px; color: #666"><%=(deals.get(i+1).getProductType()==0?"Giao Phiếu":"Giao Hàng") %></span>
																					</strong>
																					</td>
																				</tr>
																			</tbody>
																		</table>
																	</td>
																</tr>
															</tbody>
														</table>
														<% } %>
													</td>
												</tr>
												<% } 
												} %>
												
												
												<tr>
													<td height="15" align="center" style="background: #fff"
														colspan="3">&nbsp;</td>
												</tr>
												<tr>
													<td valign="middle" align="center"
														style="font-size: 15px; background: #d0e2bb; padding: 15px 0px 5px 0px"
														colspan="3"><strong>Mọi thắc mắc vui lòng
															liên hệ: <a target="_blank"
															href="mailto:info@orabuy.com">info@orabuy.com</a>
														</span>
													</strong>
													</td>
												</tr>
												<tr>
													<td align="center" style="font-size: 10px; background: #89b656; color: #fff; padding: 10px 0px"
														colspan="3">
														Bạn nhận được thư này do địa chỉ email đã được đăng ký tại Orabuy.com<br>
														<span style="font-size:12px;">Để ngưng nhận email thông báo các khuyến mãi từ  Orabuy, vui lòng 
															<a target="_blank" title="click vào đây" href="<%=UrlHelper.getServerUrl(request) + "/cancel-email"%>"><span style="text-decoration:underline;color:#fff">click vào đây.<br></span></a></span>
														</a>
													</td>
												</tr>
											</tbody>
										</table></td>
								</tr>
							</tbody>
						</table>
					</div>
				</center>
			</div>
			<div class="yj6qo"></div>
			<div class="adL"></div>
		</div>
	</div>
</body>
</html>